import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args)
    {
        int corePoolSize = 10;
        int maxmimumSize = 15;
        int keepAliveTime = 5;
        ThreadFactory threadFactory = Executors.defaultThreadFactory();
        BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(10);
        RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                corePoolSize,
                maxmimumSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                blockingQueue,
                threadFactory,
                rejectedExecutionHandler
        );
        for(int i = 0; i < 30; i++){
            threadPoolExecutor.submit(new Runnable() {
                @Override
                public void run() {

                    try {
                        System.out.println(Thread.currentThread().getName() + "开始执行");
                        Thread.sleep(1000);
                        System.out.println(Thread.currentThread().getName() + "执行完毕");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
    }
}